package com.wittams.gritty;

import java.awt.Color;

public class StyleState {
	private Style currentStyle;
	private final Style initialStyle;
	
	/*
	public StyleState()
	{
		this(new Style());
	}
	*/
	public StyleState(Style style)
	{
		if(style==null) throw new IllegalArgumentException("Invalid constructor definition - style cannot be null");
		this.initialStyle= style.clone();
		currentStyle = style.clone();
	}
	
	private void rollStyle() {
		if(currentStyle!=null)
		{
			currentStyle = currentStyle.clone();
		}  else {
			currentStyle= initialStyle;
		}
	}
	
	public Style getCurrent() {
		return Style.getCanonicalStyle(currentStyle);
	}
	
	public void setCurrentBackground(final Color bg) {
		rollStyle();
		currentStyle.setBackground(bg);
	}

	public void setCurrentForeground(final Color fg) {
		rollStyle();
		currentStyle.setForeground(fg);
	}

	public void setOption(Style.Option opt, boolean val){
		rollStyle();
		currentStyle.setOption(opt, val);
	}

	public void reset(){
		rollStyle();
		currentStyle.setForeground(getInitialStyle().getForeground());
		currentStyle.setBackground(getInitialStyle().getBackground());
		currentStyle.clearOptions();
		
	}
	public Style getInitialStyle() {
		return initialStyle;
	}
	
}
